package com.ebai.product.management.repository.system;

import java.util.List;

import javax.persistence.Table;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import com.ebai.product.management.base.utils.SysCode;
import com.ebai.product.management.model.entity.Dept;

@Repository
@Table(name="dept")
@Qualifier("deptRepository")
public interface DeptRepository extends CrudRepository<Dept, String>, JpaSpecificationExecutor<Dept>{

	public Dept save(Dept dept);

    public void deleteByPid(String pid);

    public void delete(Dept entity);

    public Dept findByPid(String pid);

    public List<Dept> findAll();

    Page<Dept> findAll(Specification<Dept> specification, Pageable pageable);
    
    @Query("select t from Dept t where t.isDelete='"+SysCode.DICT_TYSF.NO+"' order by t.sortOrder ")
    public List<Dept> selectDeptList();
    
    @Query("select t from Dept t where t.isDelete='"+SysCode.DICT_TYSF.NO+"' and t.parentId=:parentId order by t.sortOrder ")
    public List<Dept> selectDeptByParentId(@Param("parentId") String parentId);
}
